package com.ruan.controller;

import com.ruan.pojo.PaymentDetails;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @PostMapping("/verifyPayment")
    public ResponseEntity<String> verifyPayment(@RequestBody PaymentDetails paymentDetails) {
        // 验证交易流水号和支付时间
        if (isValidTransactionId(paymentDetails.getTransactionId())
                && isValidPaymentTime(paymentDetails.getPaymentTime())) {
            return ResponseEntity.ok("支付信息有效");
        } else {
            return ResponseEntity.badRequest().body("支付信息无效");
        }
    }

    private boolean isValidTransactionId(String transactionId) {
        // 可以查询数据库或其他存储来验证交易流水号的有效性
        return transactionId != null && !transactionId.isEmpty();
    }

    private boolean isValidPaymentTime(String paymentTime) {
        // 可以与当前时间进行比较来验证支付时间的有效性
        // 这里简单地检查支付时间是否为空
        return paymentTime != null && !paymentTime.isEmpty();
    }
}
